﻿using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EternalRoad.Components
{
    class CameraComponent : DrawableGameComponent
    {
        /// <summary>
        /// Kameraposition
        /// </summary>
        public Vector2 Center { get; private set; }
        /// <summary>
        /// Sichtbarer Bereich
        /// </summary>
        public Rectangle ViewPort { get; set; }

        private WorldComponent world { get; set; }
        private InputComponent input { get; set; }

        private Vector2 renderSize;

        public CameraComponent(Game game, WorldComponent worldComponent, InputComponent inputComponent) 
            : base(game)
        {
            world = worldComponent;
            input = inputComponent;
        }

        protected override void LoadContent()
        {
            SetRenderSize(new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height));
            base.LoadContent();
        }

        public override void Update(GameTime gameTime)
        {
            Center = new Vector2(10, 10);
            RecalcViewPort();
        }

        public void SetRenderSize(Vector2 renderSize)
        {
            this.renderSize = renderSize;
            RecalcViewPort();
        }

        private void RecalcViewPort()
        {
            float offsetX = (Center.X) - (renderSize.X / 2);
            float offsetY = (Center.Y) - (renderSize.Y / 2);

            ViewPort = new Rectangle((int)offsetX, (int)offsetY, (int)renderSize.X, (int)renderSize.Y);
        }
    }
}
